package com.example.zsf.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import androidx.fragment.app.Fragment;

import com.blankj.utilcode.util.PhoneUtils;
import com.blankj.utilcode.util.RegexUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.example.zsf.R;
import com.example.zsf.activity.account.LoginActivity;
import com.example.zsf.base.ZSFClearFocus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class InputPhoneFragment extends Fragment implements ZSFClearFocus {
    @BindView(R.id.editTextPhone)
    EditText editTextPhone;
    @BindView(R.id.verification_code_bt)
    Button verificationCodeBt;
    private Unbinder unbinder;
    private LoginActivity.FetchVerificationCodeListener listener;

    public InputPhoneFragment() {
    }

    public InputPhoneFragment(LoginActivity.FetchVerificationCodeListener listener) {
        this.listener = listener;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_input_phone, container, false);
        unbinder = ButterKnife.bind(this, inflate);
        initUI();
        return inflate;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }


    private void initUI() {

    }


    @Override
    public void clearFocus() {

    }

    @OnClick(R.id.verification_code_bt)
    public void onViewClicked() {
        if (listener != null) {
            String s = editTextPhone.getText().toString();
            if (s.equals("")) {
                ToastUtils.showShort("手机号不能为空！");
            } else if (!RegexUtils.isMobileExact(s)) {
                ToastUtils.showShort("请输入正确的手机号码");
            } else {
                listener.fetchVerificationCode(s);
            }
        }
    }


}